#include "trajectory.h"
#include <QString>
#include <algorithm>
#include <functional>

using namespace mlgesture;
using namespace std;

struct lessString : public binary_function<string, string, bool> {
	bool operator()(string x, string y) { return QString::fromStdString(x).toLower() < QString::fromStdString(y).toLower(); }
};

void Trajectory::getTrajectoryTypes(const vector<Trajectory> &trajectories, vector<string> &categories) {
	vector<string> types;
	for (vector<Trajectory>::const_iterator it = trajectories.begin(); it != trajectories.end(); ++it) {
		types.push_back(it->type_);
	}
	sort(types.begin(), types.end(), lessString());
	vector<string>::iterator newEnd = unique(types.begin(), types.end());
	int typesCount = 0;
	for (vector<string>::iterator it = types.begin(); it != newEnd; ++it, ++typesCount);
	types.resize(typesCount);
	sort(types.begin(), types.end(), lessString());
	for (int i=0; i<typesCount; i++) {
		categories.push_back(QString::fromStdString(types[i]).toLower().toStdString());
	}
}
